function userMedia(){} userMedia.prototype = { charactersCount: function() { let limit = 4000; let charactersInTextArea = document.getElementById('historyTextarea').value.length; let characteresRemaining = limit - charactersInTextArea; document.getElementById('charactersRemaining').innerText = characteresRemaining; }, croppieInit: function (object, productId, eventId) { this.addInputName(productId); this.addImageButtons(productId); const c = new Croppie(document.getElementById('user-photo'), { viewport: {width: 218, height: 303}, boundary: {width: 305, height: 305}, }); document.getElementById('cut').addEventListener('click', function () { c.result('blob').then(function (blob) { c.result({type: 'base64', size: 'original'}).then(function (result) { object.uploadPhoto(result, productId, eventId); object.addThumbnail(result, productId); object.setAvatarName(productId); c.destroy(); document.getElementById('file_' + productId).value = ''; $('.photo-general').remove(); document.getElementById(productId).scrollIntoView(); }); }) }); document.getElementById('cancel').addEventListener('click', function () { c.destroy(); document.getElementById('file_' + productId).value = ''; $('.photo-general').remove(); }); }, setAvatarName: function (productId) { const avatarName = document.getElementById('name').value; document.getElementById('avatar_name_' + productId).innerHTML = avatarName; }, addEditPhotoRow: function (productId, eventId) { let divPhotoGeneral = document.createElement('div'); divPhotoGeneral.setAttribute('class', 'photo-general'); divPhotoGeneral.setAttribute('id', 'photoGeneral' + productId); let divPhotoContainer = document.createElement('div'); divPhotoContainer.setAttribute('id', 'photoContainer' + productId); divPhotoContainer.setAttribute('class', 'row mt-4 photoContainer'); let divPhoto = document.createElement('div'); divPhoto.setAttribute('id', 'photo' + productId); divPhoto.setAttribute('class', 'col-md-6 center'); let divPhotoCommands = document.createElement('div'); divPhotoCommands.setAttribute('id', 'photoCommands' + productId); divPhotoCommands.setAttribute('class', 'col-md-12 text-center'); let divExampleGif = document.createElement('div'); divExampleGif.setAttribute('class', 'col-md-5 center'); divExampleGif.setAttribute('style', 'text-align:center;padding-top: 50px;'); let paragrapgDescriptionGif = document.createElement('p'); paragrapgDescriptionGif.innerText = 'Veja como enquadrar a foto'; let gifUrl = false; switch (eventId) { case 7045: case 7070: gifUrl = 'https://s3-sa-east-1.amazonaws.com/sgegeo/images/gif_default_body.gif'; break; case 7038 : gifUrl = 'https://s3-sa-east-1.amazonaws.com/sgegeo/images/gif_atletico_body.gif'; break; default: gifUrl = 'https://s3-sa-east-1.amazonaws.com/sgegeo/images/gif_default_face.gif'; } let imgExampleGif = document.createElement('img'); imgExampleGif.setAttribute('src', gifUrl); divExampleGif.appendChild(paragrapgDescriptionGif); divExampleGif.appendChild(imgExampleGif); divPhotoContainer.appendChild(divExampleGif); divPhotoContainer.appendChild(divPhoto); divPhotoContainer.appendChild(divPhotoCommands); divPhotoGeneral.appendChild(divPhotoContainer); const referenceRow = document.getElementById(productId); referenceRow.appendChild(divPhotoGeneral); }, addInputName: function (productId) { let divNameInput = document.createElement('div'); divNameInput.setAttribute('id', 'inputName' + productId); divNameInput.setAttribute('class', 'form-group text-center'); divNameInput.setAttribute('style', 'padding: 15px'); let inputName = document.createElement('input'); inputName.type = 'text'; inputName.setAttribute('id', 'name'); inputName.setAttribute('class', 'form-control'); inputName.placeholder = '* Digite o nome e sobrenome'; inputName.addEventListener('keyup', function () { if (this.value.length >= 3) { document.getElementById('cut').removeAttribute('disabled'); document.getElementById('cut').removeAttribute('class'); document.getElementById('cut').setAttribute('class', 'btn-able fc-btn btn-padrao-ativo mx-2'); } else { document.getElementById('cut').setAttribute('disabled', 'disable'); document.getElementById('cut').removeAttribute('class'); document.getElementById('cut').setAttribute('class', 'btn-disable fc-btn btn-padrao-ativo mx-2'); } }); divNameInput.appendChild(inputName); document.getElementById('photoCommands' + productId).appendChild(divNameInput); }, addThumbnail: function (base64result, productId) { const imgElement = document.getElementById('user_thumb_'+productId); const isThumbnailImgElement = document.getElementById('thumbnail_'+productId).contains(imgElement); if (isThumbnailImgElement) { document.getElementById('user_thumb_'+productId).remove(); } let imgThumbnail = document.createElement('img'); const attrImgThumbnailId = document.createAttribute('id'); attrImgThumbnailId.value = 'user_thumb_'+productId; const attrImgThumbnailSrc = document.createAttribute('src'); attrImgThumbnailSrc.value = base64result; const attrImgThumbailClass = document.createAttribute('class'); attrImgThumbailClass.value = 'avatar-thumbnail'; const attrImgThumbailBorderRadius = document.createAttribute('style'); attrImgThumbailBorderRadius.value = 'border-radius: 50%; width: 56px; height: 56px;'; imgThumbnail.setAttributeNode(attrImgThumbnailId); imgThumbnail.setAttributeNode(attrImgThumbnailSrc); imgThumbnail.setAttributeNode(attrImgThumbailClass); imgThumbnail.setAttributeNode(attrImgThumbailBorderRadius); document.getElementById('thumbnail_'+productId).appendChild(imgThumbnail); }, uploadPhoto: function (base64file, productId, eventId) { const avatarName = document.getElementById('name').value; ajaxLoader.ajaxStart(); $.ajax({ url: '/user-media/upload', data: {'file': base64file, 'productId': productId, 'avatarName': avatarName, 'eventId': eventId}, type: 'post', dataType: 'json', success: function(json) { ajaxLoader.ajaxStop(); if (!json.status) { let modalError = new Modal({ title: json.title, body : '